import { OrgUserData, OrgUserSearchModel, UserItem } from "./models";
import req from "/@/api/req";

export enum Api {
  getOrgTreeVoByName = "api/system/organizations/getOrgTreeVoByName",
  addOrganization = "api/system/organizations/addOrganization",
  updateOrganization = "api/system/organizations/updateOrganization",
  deleteOrganizationByIds = "api/system/organizations/deleteOrganizationByIds",
  pageOrganizationUsers = "api/system/organizations/pageOrganizationUsers",
  getOrganizationsAnUsersByParentId = "api/system/organizations/getOrganizationsAnUsersByParentId",
  getOrganizationUsers = "api/system/organizations/getOrganizationUsers",
  getPositions = "api/system/organizations/getPositions",
}

export function getOrgUserByParentId(companyId: string) {
  return req.get<OrgUserData>(
    {
      url: Api.getOrganizationsAnUsersByParentId,
      params: {
        companyId,
        searchText: "",
      },
    },
    {
      useGlobalLoading: false,
    }
  );
}

export function getUsers(data: OrgUserSearchModel) {
  return req.post<UserItem[]>(
    {
      url: Api.getOrganizationUsers,
      data,
    },
    {
      useGlobalLoading: false,
    }
  );
}

export function getPositions(companyId: string) {
  return req.commonPost(Api.getPositions, { companyId }, { useGlobalLoading: false });
}
